<template>
	<view class="page" :style="themeColor">
		<!---logoflex布局开始-->
		<view class="flex flex-direction flex-wrap align-center justify-center benben-flex-layout ccddLogin_flex_0">
			<image class='ccddLogin_fd0_0' mode="aspectFit" :src='STATIC_URL+"61.png"'></image>
		</view>
		<!---logoflex布局结束-->
		<!---flex布局flex布局开始-->
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout ccddLogin_flex_1">
			<view class='flex flex-wrap align-center ccddLogin_fd1_0'>
				<image class='ccddLogin_fd1_0_c0' mode="aspectFit" :src='STATIC_URL+"101.png"'></image>
				<input class='flex-sub ccddLogin_fd1_0_c1' type="number" placeholder="请输入手机号" confirm-type="done"
					:maxlength="11" placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" v-model="mobile" />
			</view>
			<view class='flex flex-wrap align-center ccddLogin_fd1_1'>
				<image class='ccddLogin_fd1_1_c0' mode="aspectFit" :src='STATIC_URL+"102.png"'></image>
				<input class='flex-sub ccddLogin_fd1_1_c1' type="number" placeholder="请输入验证码" confirm-type="done"
					:maxlength="6" placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" v-model="code" />
				<benben-send-verification-code class='flex  ccddLogin_fd1_1_c2' after-text='后重新获取' before-text='获取验证码'
					type='3' :phone="mobile"></benben-send-verification-code>
			</view>
			<text class='ccddLogin_fd1_2' @tap.stop="handleJumpDiy" data-type="redirectTo"
				:data-url="`/pages/tabBar/passwordLogin/passwordLogin`">密码登录</text>
			<view class='flex flex-wrap align-center justify-center'>
				<button class='ccddLogin_fd1_3_c0' @tap.stop="CodeLoginFunc()">登录</button>
			</view>
			<view class='flex flex-wrap align-center justify-center ccddLogin_fd1_4'>
				<text @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/registers/registers`">注册账号</text>
				<text class='ccddLogin_fd1_4_c1'>|</text>
				<text @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/forgetPassword/forgetPassword`">忘记密码</text>
			</view>
		</view>
		<!---flex布局flex布局结束-->
		<view class="flex flex-direction flex-wrap align-center benben-position-layout flex ccddLogin_flex_2">
			<block v-if="weixin_show">
				<view class='flex flex-wrap align-center'>
					<view class='flex flex-wrap align-center ccddLogin_fd2_0_c0'>
					</view>
					<text class='ccddLogin_fd2_0_c1'>快捷登录</text>
					<view class='flex flex-wrap align-center ccddLogin_fd2_0_c2'>
					</view>
				</view>
				<image class='ccddLogin_fd2_1' :src='STATIC_URL+"103.png"' @tap.stop="wxLogin"></image>
			</block>
			
			<view class='flex flex-wrap align-center ccddLogin_fd2_2'>
				<benben-flex-switch-new class-name='flex flex ccddLogin_fd2_2_c0' v-model="is_tick" :disabled='false'>
					<template v-slot:checked>

						<view class='flex flex position-relative align-center'>
							<image class='ccddLogin_checkfd2_2_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"80.png"'>
							</image>
						</view>

					</template>
					<template v-slot:unchecked>

						<view class='flex flex position-relative justify-end align-center'>
							<image class='ccddLogin_noCheckfd2_2_c0_c1_c0' mode="aspectFit" :src='STATIC_URL+"83.png"'>
							</image>
						</view>

					</template>
				</benben-flex-switch-new>
				<text class='ccddLogin_fd2_2_c1'>已阅读并同意</text>
				<text class='ccddLogin_fd2_2_c2' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/userAgreement/userAgreement?type=1`">《用户注册协议》</text>
				<text class='ccddLogin_fd2_2_c3'>与</text>
				<text class='ccddLogin_fd2_2_c4' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/userAgreement/userAgreement?type=2`">《隐私政策》</text>
			</view>

		</view>
		<view :style="{height: '274rpx'}"></view>

	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				"mobile": "",
				"code": "",
				"is_tick": false,
				"data": {
					"userinfo": {
						"user_token": "",
						"id": "",
						"head_img": "",
						"user_name": "",
						"user_nickname": "",
						"user_email": "",
						"sex": "",
						"user_type": "",
						"mobile": "",
						"birthday": "",
						"address": "",
						"address_code": "",
						"client_id": "",
						"invite_code": "",
						"is_finger": "",
						"autograph": ""
					}
				},
				"user_token": "",
				"weixin_show": false
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			this.isShow_weixin();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 是否隐藏微信登录  post64547dcf18b52
			isShow_weixin() {
				let appVersion = '';
				// #ifdef APP-PLUS
				plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
				  appVersion = widgetInfo.versionCode
				})
				// #endif
				this.$api.post(global.apiUrls.post64547dcf18b52, {
					app_version: appVersion ? appVersion : 100,
					type: uni.getSystemInfoSync().platform == 'android' ? 'android' : 'ios'
				}).then(res => {
					if (res.data.code == 1) {
						this.weixin_show = false;
					} else {
						this.weixin_show = true;
					}
				})
			},
			//验证码登录
			async CodeLoginFunc() {
				if (!validate(this.mobile, 'require')) {
					this.$message.info('手机号不能为空');
					return false;
				}
				if (!validate(this.mobile, 'phone')) {
					this.$message.info('请输入正确的手机号');
					return false;
				}
				if (!validate(this.code, 'require')) {
					this.$message.info('请输入验证码');
					return false;
				}
				if (!validate(this.code, 'captcha')) {
					this.$message.info('请输入正确的验证码');
					return false;
				}
				if (this.is_tick === false) {
					this.$message.info('请阅读并同意《用户注册协议》与《隐私政策》');
					return false;
				}
				//请求方法
				//数据验证

				let datadata = await this.$api.post(global.apiUrls.post64365758ee363, {
					mobile: this.mobile,
					code: this.code,
					type: 3
				});
				if (datadata.data.code != 1) {
					this.$message.info(datadata.data.msg);
					return
				}
				let infodata = datadata.data;
				this.data = infodata.data
				this.$store.commit('updateUserInfo', this.data.userinfo)
				this.$store.commit('saveToken', this.data.userinfo.user_token)
				uni.$emit('appLoginSuccess');
				this.$message.info(datadata.data.msg);
				setTimeout(() => {
					this.toHomeDiy();
				}, 800)
			},
			
			/**
			 * @event 微信登陆
			 */
			wxLogin() {
				let _this = this;
				if (!_this.is_tick) return _this.$message.info('请阅读并同意《用户注册协议》与《隐私政策》');
				// #ifdef APP-PLUS
				// 如果是app环境打开微信
				if (
					plus.runtime.isApplicationExist({
						pname: "com.tencent.mm",
						action: "weixin://",
					})
				) {
					uni.getProvider({
						service: "oauth",
						success: function(res) {
							console.log(res);
							// 如果支持微信等，就执行 wx_login_fn 方法
							if (~res.provider.indexOf("weixin")) {
								_this.wx_login_fn();
							}
						},
						fail: function(err) {
							// api错误是打印错误
							console.log(err);
						},
					});
				} else {
					// 调起失败时提醒用户
					_this.$message.info("请安装微信后再使用此功能");
				}
				// #endif
			},
			/**
			 * @function 微信授权登录
			 */
			wx_login_fn() {
				let _this = this;
				/**
				 * @desc uniapp的登陆api
				 * @param {String} provider - 登录服务提供商
				 * @param {login~success} loginRes - 接口调用成功时的回调函数
				 */
				uni.login({
					provider: "weixin",
					// onlyAuthorize: true, // 微信登录仅请求授权认证
					/**
					 * @callback login~success
					 * @param {Object} loginRes - api返回来的信息
					 */
					success: function(loginRes) {
						console.log(loginRes);
						/**
						 * @desc 获取用户信息
						 * @param {String} provider - 登录服务提供商
						 * @param {Funtion} success - 接口调用成功时的回调函数
						 */
						uni.getUserInfo({
							provider: "weixin",
							/**
							 * @callback success
							 * @param {Object} infoRes - api返回来的信息
							 */
							success: function(infoRes) {
								// 显示加载状态
								uni.showLoading({
									title: '加载中...',
								});
								/**
								 * @let {String} nickName - 结构出来的变量昵称
								 * @let {String} avatarUrl - 解构出来的头像链接
								 * @let {String} gender - 结构出来的性别
								 */
								let {
									nickName,
									avatarUrl,
									gender
								} = infoRes.userInfo;
					
								/**
								 * @description 第三方登录请求接口
								 */
								_this.$api.post(global.apiUrls.post64366e252b3aa, {
									wx_openid: infoRes.userInfo.openId,
								}).then(res => {
									uni.hideLoading();
									_this.$message.info(res.data.msg);
									if (res.data.code == 1) {
										global.tempUserLoginInfo = infoRes.userInfo;
										_this.$store.commit('updateUserInfo',res.data.data.userinfo)
										_this.$store.commit('saveToken', res.data.data.userinfo.user_token)
										uni.$emit('appLoginSuccess');
										setTimeout(() => {
											_this.toHomeDiy();
										}, 800)
									} else if (res.data.code == -999) {
										/**
										 * @description 清除当前页面，跳转到绑定手机页面
										 */
										setTimeout(() => {
											let data = {
												unionId: infoRes.userInfo.unionId,
												openId: infoRes.userInfo.openId,
												sex: infoRes.userInfo.gender,
												nickName: infoRes.userInfo.nickName,
												avatarUrl: infoRes.userInfo.avatarUrl,
												authType: "wx_unionid"
											}
											uni.setStorageSync('weixinInfo', data);
											uni.redirectTo({
												url: "/pages/dlzc/bindMobileNumber/bindMobileNumber"
											})
										}, 800)
										// 点击手机号账号登录按钮
									}
								})
							},
							fail: function(err) {
								uni.hideLoading();
								console.log(err);
							}
						});
					},
					fail: function(err) {
						uni.hideLoading();
						console.log(err);
					},
				});
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}

	.ccddLogin_flex_0 {
		padding: 150rpx 0rpx 0rpx 0rpx;
	}

	.ccddLogin_fd0_0 {
		width: 180rpx;
		height: 180rpx;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
	}

	.ccddLogin_flex_1 {
		padding: 80rpx 32rpx 0rpx 27rpx;
	}

	.ccddLogin_fd1_4_c1 {
		margin: 0rpx 40rpx 0rpx 40rpx;
	}

	.ccddLogin_fd1_4 {
		margin: 32rpx 0rpx 0rpx 0rpx;
		color: #999999;
		font-size: 28rpx;
		line-height: 34rpx;
		font-weight: 400;
	}

	.ccddLogin_fd1_3_c0 {
		background: rgba(62, 128, 246, 1);
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		height: 88rpx;
		line-height: 88rpx;
		width: 638rpx;
		font-weight: 500;
	}

	.ccddLogin_fd1_2 {
		margin: 32rpx 0rpx 48rpx 0rpx;
		line-height: 34rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		text-align: right;
	}

	.ccddLogin_fd1_1_c2 {
		font-size: 28rpx;
		color: rgba(48, 131, 255, 1);
		font-weight: 400;
	}

	.ccddLogin_fd1_1_c1 {
		line-height: 125rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-decoration: none;
		height: 125rpx;
	}

	.ccddLogin_fd1_1_c0 {
		width: 34rpx;
		height: 34rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.ccddLogin_fd1_1 {
		border-bottom: 1px solid #eee;
		background: rgba(255, 255, 255, 0.39);
		height: 125rpx;
	}

	.ccddLogin_fd1_0_c1 {
		line-height: 125rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-decoration: none;
		height: 125rpx;
	}

	.ccddLogin_fd1_0_c0 {
		width: 34rpx;
		height: 34rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.ccddLogin_fd1_0 {
		border-bottom: 1px solid rgba(238, 238, 238, 1);
		background: rgba(255, 255, 255, 0.39);
		height: 125rpx;
	}

	.ccddLogin_flex_2 {
		background: #fff;
		width: 750rpx;
		height: 274rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		background-size: 100% auto !important;
	}

	.ccddLogin_fd2_2_c4 {
		color: rgba(65, 119, 221, 1);
		font-size: 24rpx;
		font-weight: 400;
		line-height: 32rpx;
	}

	.ccddLogin_fd2_2_c3 {
		color: rgba(153, 153, 153, 1);
		font-size: 24rpx;
		font-weight: 400;
		line-height: 32rpx;
	}

	.ccddLogin_fd2_2_c2 {
		color: rgba(65, 119, 221, 1);
		font-size: 24rpx;
		font-weight: 400;
		line-height: 32rpx;
	}

	.ccddLogin_fd2_2_c1 {
		color: rgba(153, 153, 153, 1);
		font-size: 24rpx;
		font-weight: 400;
		line-height: 32rpx;
	}

	.ccddLogin_noCheckfd2_2_c0_c1_c0 {
		width: 24rpx;
		height: 24rpx;
	}

	.ccddLogin_checkfd2_2_c0_c0_c0 {
		width: 24rpx;
		height: 24rpx;
	}

	::v-deep .ccddLogin_fd2_2_c0 {
		margin: 0rpx 16rpx 0rpx 0rpx;
		transform: translateY(-3rpx);
	}

	.ccddLogin_fd2_2 {
		margin: 48rpx 0rpx 0rpx 0rpx;
		position: fixed;
		bottom: 32rpx;
	}

	.ccddLogin_fd2_1 {
		width: 80rpx;
		height: 80rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.ccddLogin_fd2_0_c2 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}

	.ccddLogin_fd2_0_c1 {
		line-height: 32rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #999999;
		padding: 0rpx 7rpx 0rpx 7rpx;
	}

	.ccddLogin_fd2_0_c0 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}
</style>